Ext.namespace("wm");
Ext.namespace("wmlib");

wmlib.loader = function (){
    var self = this;
    self.MODPATH = "/mods/";
    self.loaded = [];
    self.toLoad = [];
    self.notify = function(module){
        
            if( self.toLoad[module]){
                    wm.router.doResponse(true, self.toLoad[module]);
                    delete self.toLoad[id];
            }
            self.loaded[module] = true;
    };
    
    self.load = function(msg){
            wmlog.log("Router loading ", msg, override);
            var override = override || false;
            
            if( self.loaded[msg.params] === true && !override ){
                wmlog.log("Module[" + msg.params + "] was already loaded.");
                self.doResponse(true, msg.id);
                return;
            }else{
                self.toLoad[msg.params] = msg.id;
            }

            module = msg.params;
            modpath = self.MODPATH + module.replace(".",'/') + ".js"
            wmlog.debug("Attempting to load src file ", modpath);
            slem = new Element("script",{src:modpath});
            jQuery("head").append(slem);
            
        };

}

wm.loader = new wmlib.loader();
wm.loader.notify(-1, "wmlib.loader");